/***
 *  不常用组件生命周期之 getDeriviedStateFromProps
 *  将props和state进行关联 映射
 *
 */
import React, { Component } from 'react'

export default class App extends Component {
  render() {
    return (
      <div>
        父组件
        <Child msg="父组件传递的参数"></Child>
      </div>
    )
  }
}

class Child extends Component {
  // state = this.props
  // 将props映射到state中 产生关联
  static getDerivedStateFromProps(props, state) {
    //   console.log(props)
    //   // console.log(state)
    //   // 返回值 将赋值给state
    return { msg: props.msg }
  }
  render() {
    // console.log(this.props)
    return <div>子组件-{this.state.msg}</div>
  }
}
